//
//  FQDDetailToolBarButton.m
//  FakeQDaily
//
//  Created by mewxiv on 8/20/16.
//  Copyright © 2016 Xensius. All rights reserved.
//

#import "FQDDetailToolBarButton.h"

#import "Masonry.h"

@implementation FQDDetailToolBarButton


+ (FQDDetailToolBarButton *)buttonWithIcon:(UIImage *)iconImage detailText:(NSString *)detailText target:(id)target action:(SEL)action
{
    FQDDetailToolBarButton *button = [[FQDDetailToolBarButton alloc] init];
    button.iconImageView.image = iconImage;
    button.detailTextLabel.text = detailText;
    [button addTarget:target action:action
     forControlEvents:UIControlEventTouchUpInside];
    return button;
}

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self prepareUI];
        [self prepareConstraints];
    }
    return self;
}

- (void)prepareUI
{
    _iconImageView = [[UIImageView alloc] init];
    _iconImageView.clipsToBounds = YES;
    [self addSubview:_iconImageView];
    
    _detailTextLabel = [[UILabel alloc] init];
    [_detailTextLabel setFont:FQDRegularFontWithSize(12.0f)];
    [_detailTextLabel setTextColor:FQDHighlightColor];
    [self addSubview:_detailTextLabel];
}

- (void)prepareConstraints
{
    WeakSelf;
    
    [_iconImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(weakSelf);
    }];
    
    [_detailTextLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.iconImageView.mas_right).offset(1);
        make.bottom.equalTo(weakSelf.iconImageView.mas_top).offset(6.5);
    }];
}

@end
